<!--
 * @Author: your name
 * @Date: 2024-01-04 15:10:46
 * @LastEditTime: 2024-01-04 17:44:11
 * @LastEditors: MVGZ0018deMac-mini.local
 * @Description: In User Settings Edit
 * @FilePath: /weather-sys-v5/src/components/Navbar copy.vue
-->
<template>
  <div class="nav">
    <div class="logo">
      <img src="../assets/signin/scut.png" class="img" />
      <strong>华南理工大学</strong>
    </div>
    <div class="nav-menu" v-if="this.$store.state.isLogin">
      <el-menu
        :default-active="activeIndex"
        class="el-menu-demo"
        mode="horizontal"
        @select="handleSelect"
        ellipsis="false"
        background-color="#99ccff00"
      >
        <div v-for="menu in menus" :key="menu.index">
          <!-- 如果menu有items，则使用el-sub-menu -->
          <el-sub-menu
            v-if="menu.items && menu.items.length"
            :index="menu.index"
          >
            <template #title>{{ menu.title }}</template>
            <el-menu-item
              v-for="item in menu.items"
              :key="item.index"
              :index="item.index"
              >{{ item.text }}</el-menu-item
            >
          </el-sub-menu>

          <!-- 如果menu没有items，则使用el-menu-item -->
          <el-menu-item v-else :index="menu.index">{{
            menu.title
          }}</el-menu-item>
        </div>
      </el-menu>
      <div class="nav-user">
        <div class="avatar">
          <img class="avatar-img" src="../assets/User.png" />
        </div>
        <p class="nav-uid">{{ this.$store.state.userinfo.uid }}</p>
        <el-button @click="Loginout">退出登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { ElMenu, ElSubmenu, ElMenuItem } from "element-plus";

export default {
  name: "Navbar",
  components: {
    ElMenu,
    ElSubmenu,
    ElMenuItem,
  },
  data() {
    return {
      activeindex: "predict",
      menus: [
        {
          index: "1",
          title: "综合监测",
          items: [
            {
              index: "1-1",
              text: "天气监测",
              route: "/weather",
            },
            {
              index: "1-2",
              text: "灾害监测",
              route: "/disaster",
            },
          ],
        },
        {
          index: "2",
          title: "识别预警",
          items: [
            {
              index: "2-1",
              text: "识别",
              route: "/identify",
            },
            {
              index: "2-2",
              text: "预警",
              route: "/alert",
            },
          ],
        },
        {
          index: "3",
          title: "靶向发布",
          items: [
            {
              index: "3-1",
              text: "预警信号",
              route: "/",
            },
            {
              index: "3-2",
              text: "精准靶向发布",
              route: "/",
            },
          ],
        },
        {
          index: "4",
          title: "模型与决策",
        },
      ],
    };
  },
  methods: {
    handleselect(e) {
      console.log(e);
    },
    toMy() {
      this.activeindex = "my";
      this.$router.push({
        path: "/my",
      });
    },
    toWind() {
      this.activeindex = "wind";
      this.$router.push({
        path: "/wind",
      });
    },
    toNino() {
      this.activeindex = "nino";
      this.$router.push({
        path: "/nino",
      });
    },
    toPredict() {
      this.activeindex = "predict";
      this.$router.push({
        path: "/",
      });
    },
    toWaterPredict() {
      this.activeindex = "water";
      this.$router.push({
        path: "/water",
      });
    },
    togd() {
      this.activeindex = "gd";
      this.$router.push({
        path: "/gd",
      });
    },
    toRadar() {
      this.activeindex = "rainfall";
      this.$router.push({
        path: "/rainfallP",
      });
    },
    toRainfall() {
      this.activeindex = "rainfall";
      this.$router.push({
        path: "/rainfall",
      });
    },

    toDbz() {
      this.activeindex = "dbz";
      this.$router.push({
        path: "/radar",
      });
    },
    toDbzp() {
      this.activeindex = "dbzp";
      this.$router.push({
        path: "/DBZP",
      });
    },
    navigateTo(item) {
      this.activeindex = item.index;
      this.$router.push({
        path: item.route,
      });
    },
    Loginout() {
      this.$store.commit("Loginout");
      this.$router.push({
        path: "/",
      });
    },
    toTyphoon() {
      // window.location.href = "http://47.112.166.50:7755/"
      window.open("http://47.112.166.50:7755/", "_blank");
    },
  },
  mounted() {
    this.activeindex = this.$route.fullPath.substring(1);
  },
};
</script>

<style scoped>
.nav {
  background: linear-gradient(to right, #99ccff, #ccffff);
  border-radius: 10px;
  display: flex;
  align-items: center;
  height: 80px;
  justify-content: space-between; /* 确保元素之间的空间均匀分布 */
  width: 100%; /* 使导航栏填满容器宽度 */
}

.logo {
  display: flex;
  align-items: center;
  height: 100%;
}

.logo img {
  height: 70%;
  margin-left: 10px;
}

.logo strong {
  margin-left: 20px;
}

.nav-menu {
  display: flex;
  justify-content: center;
  flex: 0 0 60%;
}

.nav-user {
  display: flex;
  align-items: center;
  flex: 0 0 20%;
}

.nav-user .avatar {
  border-radius: 50%;
  overflow: hidden;
  width: 3vw;
  height: 3vw;
  display: flex;
  justify-content: center;
  position: relative;
}

.nav-user .avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.nav-uid {
  margin: 0 10px;
  color: gray;
  font-weight: bold;
  font-size: 1vw;
}

.el-button {
  background: linear-gradient(to right, #8bbbed, #e8f4ff);
  border: none;
  border-radius: 5px;
  box-shadow: 0 0 5px rgba(18, 27, 89, 0.5);
  color: black;
}

.el-button:hover {
  background: linear-gradient(to left, #8bbbed, #e8f4ff);
}

.el-menu-demo {
  border-bottom: solid 0px !important;
  width: 45vw;
  display: flex;
}
</style>
